#include <stdio.h>

/* Returns a * b (mod m). */
static int modmul(int a, int b, int m)
{
    return (long long)a * b % m;
}

/* Returns a ^ b (mod m). */
static int modpow(int a, int b, int m)
{
    int x = 1;
    for (; b; b >>= 1)
    {
        if (b & 1)
            x = modmul(x, a, m);
        a = modmul(a, a, m);
    }
    return x;
}

/* Miller-Rabin test for n = 2^s*d+1 against witness a (a < n). */
static int miller_rabin(int n, int s, int d, int a)
{
    /* Compute x = a^d mod n and check whether x == +/- 1 (mod n). */
    int x = modpow(a, d, n);
    if (x == 1 || x == n - 1)
        return 1;

    /* Check if any of (a^d)^2, (a^d)^4, ... == -1 (mod n). */
    while (--s > 0)
    {
        x = modmul(x, x, n);
        if (x == n - 1)
            return 1;
    }

    /* Test failed. */
    return 0;
}

static int is_prime(int n)
{
    static const int candidates[3] = { 2, 7, 61 };
    int i, s, d;

    /* Test the first few small numbers. */
    if (n <= 1)
        return 0;
    if (n == 2)
        return 1;
    if (n % 2 == 0)
        return 0;
    if (n < 9)
        return 1;
    if (n % 3 == 0 || n % 5 == 0 || n % 7 == 0)
        return 0;

    /* Decompose n-1 = 2^s * d. */
    for (s = 0, d = n - 1; d % 2 == 0; d /= 2, s++);

    /* Check every candidate witness. If any of them fails, n is composite. */
    for (i = 0; i < 3 && candidates[i] < n; i++)
    {
        if (!miller_rabin(n, s, d, candidates[i]))
            return 0;
    }
    return 1;
}

int main()
{
    int p, a;
    while (scanf("%d %d", &p, &a) == 2 && p > 0)
    {
        if (is_prime(p))                /* p is prime */
            printf("no\n");
        else if (modpow(a, p, p) == a)  /* p is pseudo-prime */
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}
